<!DOCTYPE html>
<html>
<head>
  <title>题库模板</title>
  <link href="/qcby/layuiadmin/layui/css/layui.css" rel="stylesheet" type="text/css">
  <link href="/qcby/layuiadmin/global.css" rel="stylesheet" type="text/css">
</head>
<body style="padding:10px;">
  <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
  <!--[if lt IE 9]>
  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
  <![endif]-->

<!--  <form class="layui-form" lay-filter="searchForm" id="searchForm">-->
<!--    <div class="layui-form-item">-->
<!--  &lt;!&ndash;    <div class="layui-inline">&ndash;&gt;-->
<!--  &lt;!&ndash;      <label class="layui-form-label">学科</label>&ndash;&gt;-->
<!--  &lt;!&ndash;      <div class="layui-input-inline">&ndash;&gt;-->
<!--  &lt;!&ndash;        <input type="tel" name="project"  autocomplete="off" class="layui-input">&ndash;&gt;-->
<!--  &lt;!&ndash;      </div>&ndash;&gt;-->
<!--  &lt;!&ndash;    </div>&ndash;&gt;-->
<!--      <div class="layui-inline">-->
<!--        <label class="layui-form-label">题目</label>-->
<!--        <div class="layui-input-inline">-->
<!--          <input type="tel" name="topic"  autocomplete="off" class="layui-input">-->
<!--        </div>-->
<!--      </div>-->
<!--      <div class="layui-inline">-->
<!--        <div class="layui-input-inline">-->
<!--          <button class="layui-btn" lay-submit="" lay-filter="doSearch">提交</button>-->
<!--          <button type="reset"  class="layui-btn layui-btn-primary">重置</button>-->
<!--        </div>-->
<!--      </div>-->
<!--    </div>-->
<!--  </form>-->

  <div class="demoTable">
    搜索题目：
    <div class="layui-inline">
      <input class="layui-input" name="topic" id="demoReload" autocomplete="off">
    </div>
    <button class="layui-btn" data-type="reload">搜索</button>
  </div>

  <!--表格数据开始-->
  <table id="test" lay-filter="test" ></table>
  <script type="text/html" id="xuhao"></script>


  <script src="/qcby/layuiadmin/layui/layui.js"></script>
  <script src="/qcby/layuiadmin/modules/cookie.js"></script>
  <script>
    layui.use(["element", "jquery", "layer", "form","table"], function () {
      var element = layui.element;
      var $ = layui.jquery;
      var layer = layui.layer;
      var form = layui.form;
      var table = layui.table;

      let cookie = layui.cookie;
      let session = $.cookie('the_cookie');
      if(session == null || session == ""){
        layer.alert("您还未登录，请先登录",{icon:5},function () {
          location.href="/qcby/views/user/login.html";
        });
      }

      let  myurl = "/qcby/student/errlist";
      //初始化表格
      var myTable = table.render({
        elem: '#test'
        ,title:"我的表格"
        ,height: "full"
        ,url: myurl //数据接口
        ,toolbar:"#myToolBar"
        ,defaultToolbar:[]
        ,page:true
        //,limit:5
        //,limits:[30,60,90]
        ,loading:true
        ,totalRow: true
        // ,initSort: {
        //   field: 'id' //排序字段，对应 cols 设定的各字段名
        //   ,type: 'asc' //排序方式  asc: 升序、desc: 降序、null: 默认排序
        // }
        ,text:{
          none: '暂无数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
        }
        ,cols: [
          [ //表头
            {type: 'checkbox', fixed: 'left'}
            // ,{field: 'id', title: 'ID', width:80}
            ,{field: 'xuhao', title: '序号', width:80,templet:'#zizeng',type: 'numbers',}
            ,{field: 'project', title: '学科',edit:"text",align:"center", }
            ,{field: 'topic', title: '题目',edit:"text",align:"center", }
            ,{field: 'type', title: '题型' ,templet: function (data) {
                return data.type == 1 ? "单选" :(data.type == 2 ?"多选" : "简答");
              }}
            ,{field: 'a', title: '选项A',}
            ,{field: 'b', title: '选项B',}
            ,{field: 'c', title: '选项C', }
            ,{field: 'd', title: '选项D', }
            ,{field: 'errAnswer', title: '我的答案',edit:"text"}
            ,{field: 'answer', title: '正确答案',edit:"text"}
            ,{field: 'parsing', title: '解析', edit:"text"}

            // ,{fixed: 'right', title:'操作', toolbar: '#myTool', width:150,align:"center"}
          ]
        ]
        ,id: 'testReload'
      })

      //查询数据
      form.on('submit(doSearch)', function(data){
        data = $(data.form).serialize();
        console.log(data);
        $.get("data/searchData?"+data,function(){
          myTable.reload();
        })
        return false;
      });

      var active = {
        reload: function(){
          var demoReload = $('#demoReload');

          //执行重载
          table.reload('testReload', {
            page: {
              curr: 1 //重新从第 1 页开始
            }
            ,where: {
              key: {
                topic: demoReload.val()
              }
            }
          }, 'data');
        }
      };

      $('.demoTable .layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
      });

    })
  </script>
</body>
</html>
